package cn.gok.oop;

class Person{
    private String name;
    private String sex;
    private int age;
    private int isMarried;

    public Person(String name, String sex, int age, int isMarried) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.isMarried = isMarried;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                ", isMarried=" + isMarried +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getIsMarried() {
        return isMarried;
    }

    public void setIsMarried(int isMarried) {
        this.isMarried = isMarried;
    }

    public void study(String school){
        System.out.println(this.name+"在"+school+"学习");
    }

    public static boolean marryWith(Person p1, Person p2){
        if((p1.isMarried==0)&&(p2.isMarried==0)){
            System.out.println("俩个人都是单身");
            if((p1.sex=="男")&&(p2.sex=="女")){
                System.out.println("是异性可以结婚");
                if((p1.age>=20)&&(p2.age>=19)){
                    System.out.println("达到可结婚年龄,新婚快乐");
                    return true;
                }else {
                    System.out.println("没有达到结婚年龄");
                }
            }
            else {
                System.out.println("同性不能结婚");
                           }
        }else {
            System.out.println("有人已经结婚了");
        }
        return false;
    }

}
public class homework3 {
    public static void main(String[] args) {
        Person p1=new Person("小明","男",22,0);
        Person p2=new Person("小红","女",21,0);
        System.out.println(Person.marryWith(p1,p2));
        Person student=new Person("小明","男",22,0){
            @Override
            public void study(String school) {
                System.out.println(getName()+"在"+school+"学习了4年");

            }
        };
        System.out.println("--------------------------------------");
        p1.study("泉州职业技术大学");
        System.out.println("--------------------------------------");
        student.study("泉州职业技术大学");
    }
}
